// 改置轮播图数据的模块，涉及到多个页面使用，所有将这个数据使用pinia维护
import { defineStore } from 'pinia'
import http from '@/utils/request'
import { getCateList, HotGoodsType, hotLsit, newGoodLsit } from '@/types/homeTs/homeType'
import { ApiRes } from '@/types/global'
export default defineStore('home', {
  state: () => ({
    // 数据
    slideList: [] as getCateList[],
    // 新鲜好物
    newGoodList: [] as newGoodLsit[],
    // 人气推荐
    hotItemsList: [] as hotLsit[],
    // 热门商品数据
    hotGoods: [] as HotGoodsType[]
  }),
  actions: {
    // 方法及发送 请求
    async getSildeList() {
      const res = await http.get<ApiRes<getCateList[]>>('/home/banner')
      this.slideList = res.data.result
      console.log(`home`)
    },
    // 新鲜好物的请求
    async getNewGoodList() {
      const res = await http.get<ApiRes<newGoodLsit[]>>('/home/new')
      console.log(`新鲜好物数据`, res.data.result)
      this.newGoodList = res.data.result
    },
    // 人气推荐的请求
    async getHotItemsList() {
      const res = await http.get<ApiRes<hotLsit[]>>('/home/hot')
      console.log(`人气推荐`, res.data.result)
      this.hotItemsList = res.data.result
    },
    // 热门商品的请求
    async getHotGoods() {
      const res = await http.get<ApiRes<HotGoodsType[]>>('/home/brand')
      this.hotGoods = res.data.result
    }
  },
  getters: {
    // 计算方法
  }
})
